package com.zztpc.ljl.myapplication;

import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;

import java.util.ArrayList;
import java.util.List;


public class TwoFragment extends Fragment {


    public TwoFragment() {
        // Required empty public constructor
    }


    // TODO: Rename and change types and number of parameters
    public static TwoFragment newInstance(String param1, String param2) {
        TwoFragment fragment = new TwoFragment();
        Bundle args = new Bundle();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_two, container, false);
        //实例化控件
        PieChart pieChart = inflate.findViewById(R.id.pir_cahrt);
        List<PieEntry> data= new ArrayList<>();

         //添加数据
        data.add(new PieEntry(1,"男"));
        data.add(new PieEntry(1,"女"));
        data.add(new PieEntry(1,"????"));

        PieDataSet pieDataSet = new PieDataSet(data, "");
        //放置数据
        PieData pieData = new PieData(pieDataSet);
        pieChart.setData(pieData);
        //pieDataSet.setColor(Color.RED,Color.BLUE);这里只能加一个颜色
        pieDataSet.setColors(Color.RED,Color.BLUE,Color.GREEN);
        pieChart.setHoleColor(Color.YELLOW);
        pieChart.setCenterText("这是一个饼图");
        //设置中间是否显示
        pieChart.setDrawHoleEnabled(false);
        return inflate;
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {

    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

    }

    @Override
    public void onDetach() {
        super.onDetach();

    }


}
